<template>
  <el-dialog v-model="isShowDialog"
             :before-close="handleClose"
             :title="title"
             draggable
             width="500px"
             append-to-body
  >
    <el-form :model="saveParams" ref="formRef" label-width="100px" :rules="rules">

    </el-form>

    <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="clickSave" v-if="!isView"> 保存 </el-button>
          <el-button @click="handleClose">取消</el-button>
        </span>
    </template>

  </el-dialog>
</template>

<script setup>
import {getCurrentInstance, onMounted} from "vue";
import {waybillSave} from "@/api/scApi";

const {proxy} = getCurrentInstance();
const props = defineProps({
  isShowDialog: {
    type: Boolean,
    default: false
  },
  title: {type: String},
  rowData: {type: Object},
  isView: {type: Boolean}
})
const emits = defineEmits(['cancel'])

function handleClose() {
  emits('cancel')
}

let saveParams = ref(JSON.parse(JSON.stringify(props.rowData)))
onMounted(() => {

  if (!saveParams.value.status) {
    saveParams.value.status = 0
  }

})
// 表单校验
const rules = ref({
  code: [{required: true, message: "快递编号不能为空", trigger: "blur"}],
  name: [{required: true, message: "快递公司不能为空", trigger: "blur"}],

});

function clickSave() {
  proxy.$refs.formRef.validate((valid, fileds) => {
    if (valid) {
      waybillSave(saveParams.value).then(res => {
        if (res.code === 200) {
          proxy.$modal.msgSuccess('保存成功')
          emits('cancel', true)
        }
      })
    }
  })
}

</script>

<style scoped lang="scss">

</style>